//获取地址栏属性，name 为参数名称
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}


// 异步调用接口
async function post_submit() {
    let data = new FormData();
    data.append('macAddress', $("#mac_address").val());
    axios.post("api/onWake", data).then(response => {
        resData = response.data;
        if (resData.state === 0) {
            document.location.href = 'result.html?macAddress=' + resData.macAddress;
        }
    })
}

// 选择mac地址下拉框
function select_mac_address() {
    $('.dropdown-menu a').click(function () {
        $('#mac_address').val($(this).attr('value'));
    });
}

// 根据调用结果刷新
function update_div() {
    document.getElementById("result").innerHTML = "魔术包已发送至&nbsp;[" + getUrlParam("macAddress") + "]<br/>请稍后检查是否成功被唤醒！";
}